package cn.edu.stu.syllabus.application;

import android.app.Application;
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;

import com.facebook.stetho.Stetho;
import com.orhanobut.logger.Logger;
import com.squareup.leakcanary.LeakCanary;

import java.util.TimeZone;

import cn.edu.stu.syllabus.switcher.DayNightSwitcher;

/**
 * Created by daidaijie on 2017/3/4.
 */

public class SyllabusApplication extends Application {

    private static final String TAG = "SyllabusApplication";

    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this.getApplicationContext();

        initLeakCanary();
        initStetho();
        initLogger();
        initInject();
        initVectorSupport();
        initDayNightMode();
        initTimeZone();
    }

    private void initLeakCanary() {
        if (LeakCanary.isInAnalyzerProcess(this)) {
            return;
        }
        LeakCanary.install(this);
    }

    private void initStetho() {
        Stetho.initializeWithDefaults(this);
    }

    private void initLogger() {
        Logger.init(TAG);
    }

    private void initInject() {
        DaggerApplicationComponent
                .builder()
                .applicationModule(new ApplicationModule(mContext))
                .build()
                .inject(this);
    }

    private void initVectorSupport() {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

    private void initDayNightMode() {
        DayNightSwitcher.getInstance().initAppMode();
    }

    private void initTimeZone() {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
    }

    public static Context getContext() {
        return mContext;
    }
}
